var size = 10;
var page;
var totalPage = 0;
var totalSize = 0;
$(function(){
    initInfos();
    $("#search1").click(function(){
        getInfos(1);
    });
});

function getInfos(pNum){
    var param = {};
    page = pNum;
    param.page = pNum;
    param.size = size;
    param.type = $("select").eq(0).val();
    param.status = $("select").eq(1).val();
    param.startTime = $("input").eq(0).val();
    param.endTime = $("input").eq(1).val();
    $(".preload").mypop();
    $.get('mission/getMissions.do?msg='+new Date().getTime(),param
    ,function(data){
        $("#missionList").find('tbody').empty();
        $(".preload").mypopClose();
        if(data == -401){
            goLoginPage();
        }else{
            showInfos(data);
        }
    });
}
function initInfos(){
}
function showInfos(data){
    var missions= data.data;
    totalPage = data.pageCount;
    totalSize = data.rowCount;
    setPager(page);
    if(missions && missions.length>0){
        for(var i=0,len=missions.length;i<len;i++){
            var res = '<tr><td>'+missions[i].id+'</td><td>'+missions[i].title
                +'</td><td>'+getStatus(missions[i].status)+'</td><td>'+missions[i].type
                +'</td><td>'+missions[i].sponsorName+'</td><td>'+missions[i].handlerName+
                '</td><td>'+missions[i].createTime+'</td><td>'+missions[i].handleTime+
                '</td><td>'+missions[i].commitTime+
                '</td><td><a href="mission/goMissionInfoPage.do?id='+missions[i].id+'">查看</a> | '
                +'<a href="javascript:;" onclick="confirmDel('+missions[i].id+')">删除</td></tr>';
            $("#missionList").find('tbody').append(res);
        }
    }else{
         $("#missionList").find('tbody').append("<tr><td colspan='10'>暂无数据</td></tr>");
    }
}
function confirmDel(id){
    if(confirm("确定删除")){
        $.get("mission/delete.do",{
            id : id
        },function(data){
            if(data == 1){
                alert("删除成功");
                getInfos(1);
            }
        });
    }
}
function setPager(cPage){
    page = cPage;
    if(totalPage > 0){
        $("#pager").pager({ pagenumber: cPage,
        pagecount: totalPage,
        datanumber:totalSize, 
        buttonClickCallback: PageClick });
    }else{
        $("#pager").hide();
    }
}
function PageClick(pageclickednumber){
    getInfos(pageclickednumber);
}
